// 不记得可百度查询得到结果


function ifELse(index) {
  if (index == 1) {
    // do something
  } else if (index == 2) {
    // do something
  } else if (index == 3) {
    // do something
  } else if (index == 4) {
    // do something
  }
}


// 优化写法1
function ifElse2(index) {
  switch (index) {
    case 1:
      // do something
      break;
    
    case 2:
      // do something
      break;
    
    case 3:
      // do something
      break;
    
    case 4:
      // do something
      break;
  
    default:
      break;
  }
}

// 优化写法2
function ifELse3(index) {
  let arr = ['1','2','3','4']
  return arr[index]
}

// 优化写法3
function ifElse4(index) {
  let a = {
    1: 1,
    2: '2',
    3: ()=> {
      // do something
    },
    4: 4
  }

  let func = a[index]
  func()
}

// 优化写法4
// 用 includes 处理多重条件

if( code === '202' || code === '203' || code === '204' ){

someMethod()

}

// 可以改成

if( ['202','203','204'].includes(code) ){

someMethod()

}